package com.maserb.monitor.remote;

import com.maserb.monitor.common.AjaxResult;
import com.maserb.monitor.common.AjaxUtils;
import com.maserb.monitor.common.Func_T;
import com.maserb.monitor.entity.card.CardRecordEntity;
import com.maserb.monitor.model.AttendanceResultModel;
import com.maserb.monitor.repository.schoolStudent.StudentAttendanceRepository;
import com.maserb.monitor.service.schoolStudent.SchoolStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 天绎考勤数据接口
 */
@Deprecated
@Controller
@RequestMapping("/timeSpace")
public class TimeSpaceController {
    @Autowired
    SchoolStudentService schoolStudentService;
    @Autowired
    StudentAttendanceRepository studentAttendanceRepository;

    /**
     * 考勤统计
     * @param clazzId
     * @param date
     * @return
     */
    @RequestMapping("/attendanceStat")
    @ResponseBody
    public AjaxResult<AttendanceResultModel> attendanceStat(final String clazzId, final String date) {
        return AjaxUtils.process(new Func_T<AttendanceResultModel>() {
            @Override
            public AttendanceResultModel invoke() throws Exception {
                Integer onDuty = studentAttendanceRepository.countByClazzAndDate(clazzId, date);
                Integer allCount = schoolStudentService.countByClass(clazzId);

                AttendanceResultModel stat = new AttendanceResultModel();
                stat.setAttendance(onDuty);
                stat.setTotal(allCount);

                return stat;
            }
        });
    }

    /**
     * 考勤记录
     * @param clazzId
     * @param date
     * @return
     */
    @RequestMapping("/attendanceList")
    @ResponseBody
    public AjaxResult<List<CardRecordEntity>> attendanceList(String clazzId, String date) {
        return AjaxUtils.process(new Func_T<List<CardRecordEntity>>() {
            @Override
            public List<CardRecordEntity> invoke() throws Exception {
                return studentAttendanceRepository.findByClazzAndDate(clazzId, date);
            }
        });
    }
}
